package cn.jy.nvr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.jy.nvr.domain.DonorFileName;
import cn.jy.nvr.domain.DonorInfo;
import cn.jy.nvr.domain.FindFileCondition;
import cn.jy.nvr.domain.FtpFileName;
import cn.jy.nvr.mapper.DonorFileNameMapper;
import cn.jy.nvr.mapper.DonorInfoMapper;
import cn.jy.nvr.mapper.FtpFileNameMapper;
@Controller
public class Maincontroller {
	@Autowired
	DonorFileNameMapper donorFileNameMapper;
	@Autowired
	DonorInfoMapper donorInfoMapper;
	@Autowired
	FtpFileNameMapper fileNameMapper;
	@RequestMapping("display/Collectin")
	public String Collecting(FindFileCondition condition,Model model ){
		DonorInfo idByCARDID = donorInfoMapper.getIDByCARDID(condition.getDonor_id().toString());
	    FindFileCondition Condition=new FindFileCondition();
	    Condition.setDonor_id( Long.valueOf(idByCARDID.getID()));
	    Condition.setTime(condition.getTime());
		DonorFileName donorFileName = donorFileNameMapper.getDonorFileNameByTimeAndDonor_ID(Condition);
		model.addAttribute(donorFileName);
		return "display/Collecting";
	}
	
	@RequestMapping("display/ForwardCollecting")
	public String ForwardCollecting(FindFileCondition condition,Model model ) throws Exception{
		System.out.println(condition.getTime());
		System.out.println(condition.getDonor_id());
		   Long cardId = condition.getDonor_id();
		   String time = condition.getTime();
		   String timeFormat =time.replace("-","");
		   System.out.println(timeFormat);
		   String cardIdTime=timeFormat+String.valueOf(cardId);
		   System.out.println(cardIdTime);
 		FtpFileName ftpFileName = fileNameMapper.getPathByRegsiterID(cardIdTime);
		model.addAttribute(ftpFileName);
		return "display/ForwardCollecting";
	}
	
	
	@RequestMapping("display/Uninstall")
	public String Uninstall(FindFileCondition condition,Model model ){
		DonorInfo idByCARDID = donorInfoMapper.getIDByCARDID(condition.getDonor_id().toString());
	    FindFileCondition Condition=new FindFileCondition();
	    Condition.setDonor_id( Long.valueOf(idByCARDID.getID()));
	    Condition.setTime(condition.getTime());
		DonorFileName donorFileName = donorFileNameMapper.getDonorFileNameByTimeAndDonor_ID(Condition);
		model.addAttribute(donorFileName);
		return "display/Uninstall";
	}
	@RequestMapping("display/Install")
	public String Install(FindFileCondition condition,Model model ){
		DonorInfo idByCARDID = donorInfoMapper.getIDByCARDID(condition.getDonor_id().toString());
	    FindFileCondition Condition=new FindFileCondition();
	    Condition.setDonor_id( Long.valueOf(idByCARDID.getID()));
	    Condition.setTime(condition.getTime());
		DonorFileName donorFileName = donorFileNameMapper.getDonorFileNameByTimeAndDonor_ID(Condition);
		model.addAttribute(donorFileName);
		return "display/Install";
	}
	@RequestMapping("display/Pucture")
	public String Pucture(FindFileCondition condition,Model model ){
		DonorInfo idByCARDID = donorInfoMapper.getIDByCARDID(condition.getDonor_id().toString());
	    FindFileCondition Condition=new FindFileCondition();
	    Condition.setDonor_id( Long.valueOf(idByCARDID.getID()));
	    Condition.setTime(condition.getTime());
		DonorFileName donorFileName = donorFileNameMapper.getDonorFileNameByTimeAndDonor_ID(Condition);
		model.addAttribute(donorFileName);
		return "display/Pucture";
	}
	@RequestMapping("display/test")
	public String teString(FindFileCondition condition,Model model ){
		return "display/test";
	}
}
